﻿package com.cilico.single.utils;


import android.app.Activity;
//import android.content.Context;
import android.content.SharedPreferences;

/**
 * 
 * @author lv.xiangan
 *
 */
public class RmsDatabase {
	private final String dbname_;
	public static final String PREFS_NAME = "single";
	Activity app_;
	SharedPreferences store_;

	public RmsDatabase(Activity app, String dbname) {
		dbname_ = dbname;
		app_ = app;
		store_ = app_.getSharedPreferences(dbname, 0);
	}

	String dbname() {
		return dbname_;
	}

	protected void deleteDB() throws Exception {
		store_.edit().remove(dbname_);
	}

	/**
	 *  根据键名提取键值
	 * @param key
	 * @return
	 */
	public String get(String key) {
		String record = null;
		try {
			record = store_.getString(key, "");
		} catch (Exception ex) {
			Utils.printException(ex);
		} finally {
		}
		return record;
	}

	/**
	 *  存储键对
	 * @param key
	 * @param value
	 */
	public void save(String key, String value) {
		try {
			SharedPreferences.Editor edit = store_.edit();
			edit.putString(key, value);
			edit.commit();
		} catch (Exception ex) {
			Utils.printException(ex);
		} finally {

		}
	}

	/**
	 *  删除存储值
	 * @param key
	 */
	public void delete(String key) {
		try {
			SharedPreferences.Editor edit = store_.edit();
			edit.remove(key);
			edit.commit();
		} catch (Exception ex) {
			Utils.printException(ex);
		}
	}
}
